/***************************************************************************
 * Open Object Oriented ANSI C                                             *
 ***************************************************************************
 * Code given under the terms of GNU General Public Licence (GPLv3)        *
 * and without any waranties of any kind including but not limitative to   *
 * waranties on merchandability or any particular applications fitness.    *
 * For more information on GNU/GPL go on :                                 *
 * "http://www.gnu.org/copyleft/gpl.html"                                  *
 *                                                                         *
 * You are allowed to use it for any purposes in the terms of GNU/GPLv3    *
 * (or more).                                                              *
 * This text MUST stay in state on copyed sources (or sources using it)    *
 * and must not be altered.                                                *
 * You are allowed to add your name at the end of the Copylefs list.       *
 ***************************************************************************
 * Copylefts List :                                                        *
 ***************************************************************************
 * 2010-03-20 Patrick PIGNOL <pignol_patrick@hotmail.com> (Original)       *
 * (Type your name here if needed)                                         *
 ***************************************************************************/
#include <stdarg.h>
#include <signal.h>
#include "Mem.h"
#include "Class.h"
#include "Exception.h"
#include "ExceptionManager.h"

void* new (void* (*pNew)(unsigned long, va_list*), unsigned long pArgsCount, ...)
{
    Class* this = 0;
    va_list vParams;
    if(!pNew)
    {
        ((ExceptionManager*)new((void*(*)(unsigned long int, va_list*))ExceptionManagerNew, 0))->throw((Exception*)new((void*(*)(unsigned long int, va_list*))ExceptionNew, 1, "New method must be not null"));
    }
    else
    {
        va_start(vParams, pArgsCount);
        this = pNew(pArgsCount, &vParams);
        if(!this)
        {
            raise(SIGABRT);
        }
        va_end(vParams);
    }
    return this;
}

void delete (Class* this)
{
    if ((this) && (this->VirtualTable) && (this->VirtualTable->Garbage))
    {
        this->VirtualTable->Garbage(this);
    }
}

